let mixin={
    data() {
        return {
        }
    },
    methods: {
        // 获取前几天后几天日期
        getDay(day){
            var today = new Date();
            var targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
            today.setTime(targetday_milliseconds);
            var tYear = today.getFullYear();
            var tMonth = today.getMonth();
            var tDate = today.getDate();
            let tHours = today.getHours();
            let tMinutes = today.getMinutes();
            let tSeconds = today.getSeconds();
            if(tHours<10){
                tHours = "0"+tHours
            }
            if(tMinutes<10){
                tMinutes = "0"+tMinutes
            }
            if(tSeconds<10){
                tSeconds = "0"+tSeconds
            }
            tMonth = this.doHandleMonth(tMonth + 1);
            tDate = this.doHandleMonth(tDate);
            return tYear+"-"+tMonth+"-"+tDate;
            //return tYear+"-"+tMonth+"-"+tDate+" "+ tHours+":"+tMinutes+":"+tSeconds;
		},

        getEnglishMonth(time){
            var en_mon_arr = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"];
            var d = new Date(time);
            let m = d.getMonth() + 1;
            m=en_mon_arr[m-1]
            return m
        },

        getMonth(time){
            var d = new Date(time);
            let m = d.getMonth() + 1;
            return m
        },

        getYear(time){
            var d = new Date(time);
            let y = d.getFullYear();
            return y
        },
        //斜杠分割  dd/mm/yy
        getDateSlash(time){
            var d = new Date(time);
            let y = d.getFullYear();
            let m = d.getMonth() + 1;
            let did = d.getDate();
            let h = d.getHours();
            // if(m<10){
            //     m= '0' + m
            // };
            var en_mon_arr = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"];
            m=en_mon_arr[m-1]
            if(did<10){
                did  = '0' + did
            };
            if(h<10){
                h  = '0' + h
            };
            let minute = d.getMinutes();
            if(minute<10){
                minute  = '0' + minute
            };
            let second = d.getSeconds();
            if(second<10){
                second  = '0' + second
            };
            return   did + '/'+m+'/'+y
        },
		doHandleMonth(month){
            var m = month;
            if(month.toString().length == 1){
                m = month;
            }
            return m;
		} ,
        // 转换日期 获得年月日
        getDate(date) {
            var d = new Date(date);
            let y = d.getFullYear();
            let m = d.getMonth() + 1;
            let did = d.getDate();
            let h = d.getHours();
            if(m<10){
            m= '0' + m
            };
            if(did<10){
            did  = '0' + did
            };
            if(h<10){
            h  = '0' + h
            };
            let minute = d.getMinutes();
            if(minute<10){
            minute  = '0' + minute
            };
            let second = d.getSeconds();
            if(second<10){
            second  = '0' + second
            };
            return  y + '-' + m + '-' + did
        },
      // 转换日期 获得年月日
      getToDayTime() {
        var d = new Date();
        let y = d.getFullYear();
        let m = d.getMonth() + 1;
        let did = d.getDate();
        if(m<10){
          m= '0' + m
        };
        if(did<10){
          did  = '0' + did
        };
        let minute = d.getMinutes();
        if(minute<10){
          minute  = '0' + minute
        };
        let second = d.getSeconds();
        if(second<10){
          second  = '0' + second
        };
        let now=(y + '-' + m + '-' + did)
        let date= new Date(Date.parse(now.replace(/-/g,   "/")));
        return date.getTime()
      },
        // 转换日期 获得年月日 时分秒
        getDate2(date) {
            var d = new Date(date);
            let y = d.getFullYear();
            let m = d.getMonth() + 1;
            let did = d.getDate();
            let h = d.getHours();
            if(m<10){
                m = '0' + m
            }
            if(did<10){
                did = '0' + did
            }
            if(h<10){
                h  = '0' + h
            };
            let minute = d.getMinutes();
            if(minute<10){
                minute  = '0' + minute
            };
            let second = d.getSeconds();
            if(second<10){
                second  = '0' + second
            };
            return  y + '-' + m + '-' + did +' ' + h+":"+minute+':'+second
		},

        // 获取星期几  this.getWeek(new Date(2020-10-20))
        getWeek(date) {
            var week;
            if(date.getDay() == 0) week = "星期日"
            if(date.getDay() == 1) week = "星期一"
            if(date.getDay() == 2) week = "星期二"
            if(date.getDay() == 3) week = "星期三"
            if(date.getDay() == 4) week = "星期四"
            if(date.getDay() == 5) week = "星期五"
            if(date.getDay() == 6) week = "星期六"
            return week;
        },

        timeStampFormatAPMPM(timeStamp){
            let date=new Date(timeStamp)
            return this.formatAMPM(date)
        },
        formatAMPM (date) {
            let hours = date.getHours();
            let minutes = date.getMinutes();
            let seconds=date.getSeconds();
            let ampm = hours >= 12 ? 'PM' : 'AM';
            hours = hours % 12;
            hours = hours ? hours : 12;
            minutes = minutes.toString().padStart(2, '0');
            let strTime = hours + ':' + minutes + ':'+seconds+' ' + ampm;
            return strTime;
        },



        getTime(str){
            var d = new Date(Date.parse(str.replace(/-/g, "/")));
            return d.getTime()
        },

        /**
         *获取几个月前的输入日期
        *{param:DateTime} date 输入日期(YYYY-MM-DD)
        *{param:number } monthNum 月数
        */
        GetPreMonthDay(date, monthNum) {
            var dateArr = date.split('-');
            var year = dateArr[0]; //获取当前日期的年份
            var month = dateArr[1]; //获取当前日期的月份
            var day = dateArr[2]; //获取当前日期的日
            var days = new Date(year, month, 0);
            days = days.getDate(); //获取当前日期中月的天数
            var year2 = year;
            var month2 = parseInt(month) - monthNum;
            if (month2 <= 0) {
                var absM = Math.abs(month2);
                year2 = parseInt(year2) - Math.ceil(absM / 12 == 0 ? 1 : parseInt(absM) / 12);
                month2 = 12 - (absM % 12);
            }
            var day2 = day;
            var days2 = new Date(year2, month2, 0);
            days2 = days2.getDate();
            if (day2 > days2) {
                day2 = days2;
            }
            if (month2 < 10) {
                month2 = '0' + month2;
            }
            var t2 = year2 + '-' + month2 + '-' + day2;
            return t2;
        },

        /**
        *获取下一个月的输入日期
        *{param:DateTime} date 输入日期(YYYY-MM-DD)
        *{param:number } monthNum 月数
        */
        GetNextMonthDay(date, monthNum) {
            var dateArr = date.split('-');
            var year = dateArr[0]; //获取当前日期的年份
            var month = dateArr[1]; //获取当前日期的月份
            var day = dateArr[2]; //获取当前日期的日
            var days = new Date(year, month, 0);
            days = days.getDate(); //获取当前日期中的月的天数
            var year2 = year;
            var month2 = parseInt(month) + parseInt(monthNum);
            if (month2 > 12) {
                year2 = parseInt(year2) + parseInt((parseInt(month2) / 12 == 0 ? 1 : parseInt(month2) / 12));
                month2 = parseInt(month2) % 12;
            }
            var day2 = day;
            var days2 = new Date(year2, month2, 0);
            days2 = days2.getDate();
            if (day2 > days2) {
                day2 = days2;
            }
            if (month2 < 10) {
                month2 = '0' + month2;
            }

            var t2 = year2 + '-' + month2 + '-' + day2;
            return t2;
        },
        /**
        * 获取AddDayCount天后的日期
        * @param AddDayCount  XX后  正整数  XX前 -正整数
        * @returns {string}
        * @constructor
        */

        GetDateStr(AddDayCount) {
        const dd = new Date();
        dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
        const y = dd.getFullYear();
        const m = (dd.getMonth() + 1) < 10 ? "0" + (dd.getMonth() + 1) : (dd.getMonth() + 1);//获取当前月份的日期，不足10补0
        const d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();//获取当前几号，不足10补0
        return y+"-"+m+"-"+d;
        },


        //通过身份证号计算年龄、性别、出生日期
        // userCard  身份证号
        // num == 1 获取出生日期
        // num == 2 获取性别
        // num == 3 获取年龄
        idCard(userCard, num) {
            //获取出生日期
            if (num == 1) {
                birth = userCard.substring(6, 10) + "-" + userCard.substring(10, 12) + "-" + userCard.substring(12, 14);
                return birth;
            }
            //获取性别
            if (num == 2) {
                if (parseInt(userCard.substr(16, 1)) % 2 == 1) {
                    return "男";
                } else {
                    return "女";
                }
            }
            //获取年龄
            if (num == 3) {
                var myDate = new Date();
                var month = myDate.getMonth() + 1;
                var day = myDate.getDate();
                var age = myDate.getFullYear() - userCard.substring(6, 10) - 1;
                if (userCard.substring(10, 12) < month || userCard.substring(10, 12) == month && userCard.substring(12, 14) <= day) {
                    age++;
                }
                return age;
            }
        }
    },
}
export default mixin
